<?php

namespace app\index\controller;

use app\BaseController;
use think\facade\Db;
use app\common\model\User;
use think\facade\View;

class Index extends BaseController
{
    public function index()
    {
        $user = User::field("id,name,age")->select();
        // $res = Db::name('user')->insert([
        //     'name' => "布里1",
        //     "age" => 30, 
        // ]);
        // $res = Db::name("user")->find(2);
        // var_dump($res);
        // $user           = new User;
        // $user = User::find(4);
        // $user->name     = 'xiamen';
        // $user->age    = '7891';
        // $user->save();
        // $user->delete();

        // echo $res;
        // Db::name("user")->delete(1);
        return view("",['data' => $user]);
    }

    public function form()
    {
        return view();
    }
    public function user(){
        $data = input('post.'); // 接收post过来所有数据

        // 验证拦截 valite

        $res = Db::name('user')->insert($data);
        if ($res)
        {
            return json(['msg' => 'success','code'=>1]);
        }else{
            return json(['msg' => 'error','code' => 0]);
        }
    }
}
